//-------------------------------------------------------------------
//	Copyright (c) 2012-2014 Zhirnov Andrey
//	This file is part of the "UXGEN-ES" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#include "Platforms/Android/AFileSystem.h"

#if defined( PLATFORM_ANDROID )

namespace Engine
{
namespace Platforms
{

#	define APLATFORM()			AndroidPlatform::GetInstance()
#	define AJAVAINTERFACE()		APLATFORM()->GetJavaInterface()
	

//------------------------ IFileSystem -------------------------//
/*
=================================================
	OpenResource
=================================================
*/
	bool IFileSystem::OpenResource (uni_c_string resname, RFilePtr &file) const
	{
		using namespace android;

		AAsset *	asset = AAssetManager_open( AJAVAINTERFACE()->GetAssetManager(), resname.cstr(), AASSET_MODE_UNKNOWN );
		CHECK_ERR( asset != null );

		file = new ResourceFile( asset, resname );
		return true;
	}
	
/*
=================================================
	IsResourceExist
=================================================
*/
	bool IFileSystem::IsResourceExist (uni_c_string filename) const
	{
		using namespace android;

		AAsset *	asset = AAssetManager_open( AJAVAINTERFACE()->GetAssetManager(), filename.cstr(), AASSET_MODE_UNKNOWN );

		if ( asset != null )
		{
			AAsset_close( asset );
			return true;
		}
		return false;
	}


#	undef APLATFORM
#	undef AJAVAINTERFACE

}	// Platforms
}	// Engine

#endif	// PLATFORM_ANDROID
